#include "HX711.h"

#define DT 3
#define SCK 2
#define PWM_PIN 5

HX711 scale;

long loadValue;
int pwmValue;

void setup() 
{
  Serial.begin(9600);

  scale.begin(DT, SCK);
  scale.set_scale();   // adjust calibration later
  scale.tare();        // reset scale to zero

  pinMode(PWM_PIN, OUTPUT);
}

void loop() 
{
  loadValue = scale.get_units(5);   // average of 5 readings

  // Map load value to PWM (adjust limits as needed)
  pwmValue = map(loadValue, -100, 1132000, 255, 0);

  // Limit PWM range
  pwmValue = constrain(pwmValue, 0, 255);

  analogWrite(PWM_PIN, pwmValue);

  Serial.print("Load: ");
  Serial.print(loadValue);
  Serial.print("  PWM: ");
  Serial.println(pwmValue);

  delay(50);
}